﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UI_BG_Panel : MonoBehaviour
{
    private Animator animator;
    private bool isShow = false;
    private int showingPanelCount = 0;
    void Awake()
    {
        animator = GetComponent<Animator>();
        EventManager.Add(EventNameConfig.UI.UnShow, unShow);
        EventManager.Add(EventNameConfig.UI.BG_Show, Show);
    }
    public void unShow(object[] o)
    {
        showingPanelCount--;
        if (isShow&&showingPanelCount<=0)
        {
            animator.SetBool("isShow", false);
            isShow = false;
            showingPanelCount = 0;
        }
    }

    public void Show(object[] o)
    {
        showingPanelCount++;
        if (!isShow)
        {
            isShow = true;
            animator.SetBool("isShow", true);
        }
    }

    public void unShowAll()
    {
        EventManager.Invoke(EventNameConfig.UI.UnShow, null);
    }
    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnDestroy()
    {
        EventManager.Reomve(EventNameConfig.UI.UnShow, unShow);
        EventManager.Reomve(EventNameConfig.UI.BG_Show, Show);
    }
}
